package best.driver.android.Activity.Finance;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import best.driver.android.Activity.Base.BaseActivity;
import best.driver.android.Beans.OrderFeeDetail;
import best.driver.android.Beans.TradeItemInfo;
import best.driver.android.Beans.TradeType;
import best.driver.android.R;
import best.driver.android.RequestFactory;
import best.driver.android.Utils.TimeUtil;
import best.driver.android.Utils.Util;
import best.driver.android.View.IncomeLabelView;
import best.driver.android.View.IncomeLabelView;
import best.driver.android.common.app.AppProxyFactory;
import best.driver.android.common.network.ApiObjectRequest;
import best.driver.android.common.network.ApiRequest;
import best.driver.android.common.network.BestError;
import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by xiangxuefeng on 15/12/02.
 */
public class TradeFeeActivity extends BaseActivity {

    @InjectView(R.id.ilv_total)
    IncomeLabelView mIlvTotal;

    @InjectView(R.id.ilv_transit)
    IncomeLabelView mIlvTransit;

    @InjectView(R.id.ilv_insurance)
    IncomeLabelView mIlvInsurance;

    @InjectView(R.id.ilv_subsidy)
    IncomeLabelView mIlvSubsidy;

    @InjectView(R.id.ilv_award)
    IncomeLabelView mIlvAward;

    @InjectView(R.id.ilv_fine)
    IncomeLabelView mIlvFine;

    @InjectView(R.id.ilv_withdraw)
    IncomeLabelView mIlvWithdraw;

    @InjectView(R.id.ilv_time)
    IncomeLabelView mIlvTime;

    @InjectView(R.id.ilv_remark)
    IncomeLabelView mIlvRemark;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setView(R.layout.activity_trade_fee);
        ButterKnife.inject(this, view);
        TradeItemInfo tradeInfo = (TradeItemInfo) getIntent().getSerializableExtra("tradeInfo");
        showTradeFee(tradeInfo);
        setLeftIvBak(R.drawable.icon_navibar_back);
        setTopTopic("费用明细");
    }

    private void showTradeFee(TradeItemInfo tradeItemInfo) {
        if(TradeType.ORDER_CASH.equals(tradeItemInfo.tradeType) || TradeType.ORDER_ONLINE.equals(tradeItemInfo.tradeType)) {
            showTransitFee(tradeItemInfo);
        } else if (TradeType.FINE.equals(tradeItemInfo.tradeType)) {
            showFineFee(tradeItemInfo);
        } else if (TradeType.SUBSIDY.equals(tradeItemInfo.tradeType)) {
            showAwardFee(tradeItemInfo);
        } else if (TradeType.WITHDRAWALS.equals(tradeItemInfo.tradeType)) {
            showWithdrawFee(tradeItemInfo);
        }
        mIlvTotal.setName("总计", R.color.aaaa, 14);
        mIlvTotal.setDesc(Util.getSignOnePointNumber(tradeItemInfo.amount), R.color.aaaa, 24);
        mIlvTime.setName("发生时间", R.color.c9b, 12);
        mIlvTime.setDesc(TimeUtil.convertToYMDHM(tradeItemInfo.tradeTime), R.color.aaaa, 12);
        mIlvRemark.setName("备注", R.color.c9b, 12);
        mIlvRemark.setDesc(tradeItemInfo.memo, R.color.aaaa, 12);
    }

    private void showTransitFee(TradeItemInfo tradeItemInfo) {
        if(tradeItemInfo.orderFee > 0.1) {
            mIlvTransit.setVisibility(View.VISIBLE);
            mIlvTransit.setName("运费", R.color.c9b, 12);
            mIlvTransit.setDesc(Util.getSignOnePointNumber(tradeItemInfo.orderFee), R.color.best_orange, 12);
        }
        if(tradeItemInfo.orderPremium < -0.1) {
            mIlvInsurance.setVisibility(View.VISIBLE);
            mIlvInsurance.setName("保险费", R.color.c9b, 12);
            mIlvInsurance.setDesc(Util.getSignOnePointNumber(tradeItemInfo.orderPremium), R.color.best_orange, 12);
        }
        if(tradeItemInfo.orderSubsidy > 0.1) {
            mIlvSubsidy.setVisibility(View.VISIBLE);
            mIlvSubsidy.setName("本单补贴", R.color.c9b, 12);
            mIlvSubsidy.setDesc(Util.getSignOnePointNumber(tradeItemInfo.orderSubsidy), R.color.best_orange, 12);
        }
    }

    private void showFineFee(TradeItemInfo tradeItemInfo) {
        mIlvFine.setVisibility(View.VISIBLE);
        mIlvFine.setName("罚款", R.color.c9b, 12);
        mIlvFine.setDesc(Util.getSignOnePointNumber(tradeItemInfo.amount), R.color.best_orange, 12);
    }

    private void showAwardFee(TradeItemInfo tradeItemInfo) {
        mIlvAward.setVisibility(View.VISIBLE);
        mIlvAward.setName("平台奖励", R.color.c9b, 12);
        mIlvAward.setDesc(Util.getSignOnePointNumber(tradeItemInfo.amount), R.color.best_orange, 12);
    }

    private void showWithdrawFee(TradeItemInfo tradeItemInfo) {
        mIlvWithdraw.setVisibility(View.VISIBLE);
        mIlvWithdraw.setName("司机提现", R.color.c9b, 12);
        mIlvWithdraw.setDesc(Util.getSignOnePointNumber(tradeItemInfo.amount), R.color.best_orange, 12);
    }

}
